package com.untour.im.client.handler;

import com.alibaba.fastjson2.JSON;
import com.untour.im.client.TcpClient;
import com.untour.im.codec.protocol.packet.response.body.OfflineServerResponsePacketData;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * 下线通知处理
 */
@Slf4j
public class OfflineServerResponseMessageHandler extends SimpleChannelInboundHandler<OfflineServerResponsePacketData> {


    private TcpClient tcpClient;

    public OfflineServerResponseMessageHandler(TcpClient tcpClient) {
        this.tcpClient = tcpClient;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, OfflineServerResponsePacketData responsePacketData) {
        log.info("接受到服务端强制下线通知消息:{}", JSON.toJSONString(responsePacketData));
        tcpClient.setForceOffline(true);
    }
}
